using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MBMC.Paths;

namespace MBMC.Dialogs
{
    public partial class Textures : Form
    {
        Paths.Paths p = new MBMC.Paths.Paths();
        string mbfolder;
        int linksselectedindex = 1;
        string pathtogimp;
        public Textures(string actualmbfolder, bool isgimpinstalled, string pathtoinstalledgimp)
        {
            InitializeComponent();
            mbfolder = actualmbfolder;
            if(isgimpinstalled == true)
            {
                pathtogimp = pathtoinstalledgimp;
            }
            else
            {
                pathtogimp = Application.StartupPath + "/data/apps/gimp/bin/gimp.exe";
            }
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                linkLabel1.Text = listView1.SelectedItems[0].Tag.ToString();
            }
            catch
            {
                linkLabel1.Text = "No link specificated!";
            }
        }

        private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            string url;
            //listView1.
        }

        private void Textures_Load(object sender, EventArgs e)
        {
            System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(p.Vrat_Cestu(mbfolder, MBPaths.FMDInteriors));
            foreach (System.IO.FileInfo file in di.GetFiles("*.png"))
            {
                Console.WriteLine("{0}, {1}, {2}", file.Name, file.Length, file.Extension);
                listBox1.Items.Add(file.Name);
            }
            foreach (System.IO.FileInfo file in di.GetFiles("*.jpg"))
            {
                Console.WriteLine("{0}, {1}, {2}", file.Name, file.Length, file.Extension);
                listBox1.Items.Add(file.Name);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            MatoPrograms.ImageFilters.HueChanger hc = new MatoPrograms.ImageFilters.HueChanger();
            hc.ShowDialog();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            pictureBox1.ImageLocation = p.Vrat_Cestu(mbfolder, MBPaths.FMDInteriors) + "/" + listBox1.SelectedItem.ToString();
            label5.Text = pictureBox1.ImageLocation;
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            WebBrowser wb = new WebBrowser(linkLabel1.Text);
            wb.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Choose one from tutorials below this button and click on blue link!","Where i can find help");
        }

        private void button6_Click(object sender, EventArgs e)
        {
            process1.StartInfo.FileName = pathtogimp;
            System.IO.FileInfo fi = new System.IO.FileInfo(label5.Text);
            fi.CopyTo("C:/mbmctmp/tex.png", true);
            process1.StartInfo.WorkingDirectory = Application.StartupPath + pathtogimp.Remove(pathtogimp.Length - 8, 8).ToString();
            process1.StartInfo.Arguments = @"C:\mbmctmp\tex.png";
            MessageBox.Show("Now is gimp starting and opening texture, when you finish editing texture save it(on original folder, owerwriting it) and close gimp, when is gimp closed texture will be replaced by texture edited by you!", "INFORMATION READ CAREFULLY!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            process1.Start();
            //necaka na ukoncenie procesu!
            //System.IO.FileInfo fidva = new System.IO.FileInfo(@"C:\mbmctmp\tex.png");
            //fidva.CopyTo(fi.FullName, true);
            //MessageBox.Show("File: " + fi.FullName + " copyed to: " + fidva.FullName, "INFORMATION");
        }

        private void process1_Exited(object sender, EventArgs e)
        {
            //caka na ukoncenie procesu!
            System.IO.FileInfo fidva = new System.IO.FileInfo(@"C:\mbmctmp\tex.png");
            fidva.CopyTo(fidva.FullName, true);
            MessageBox.Show("File: " + fidva.FullName + " copyed to: " + fidva.FullName, "INFORMATION");
        }
    }
}